import java.util.*;

import lib.*;

public class Example {
    public static void main(String args[]) {
        long startTime, endTime, duration;
        for (int i = 1; i <= 10; i++) {
            int[] randomArray = ExArray.randomIntArray(200000);
            int[] randomArray_copy1 = Arrays.copyOf(randomArray, randomArray.length);
            int[] randomArray_copy2 = Arrays.copyOf(randomArray, randomArray.length);

            System.out.println("第" + i + "次测试");

            startTime = System.currentTimeMillis();
            Sort.qsort(randomArray_copy1);
            endTime = System.currentTimeMillis();
            duration = endTime - startTime;
            System.out.println("\t快速排序耗时" + duration + "毫秒。");

            startTime = System.currentTimeMillis();
            Sort s = new Sort(randomArray);
            s.parallelQSort();
            endTime = System.currentTimeMillis();
            duration = endTime - startTime;
            System.out.println("\t并行快速排序耗时" + duration + "毫秒。");

            startTime = System.currentTimeMillis();
            Arrays.sort(randomArray_copy2);
            endTime = System.currentTimeMillis();
            duration = endTime - startTime;
            System.out.println("\t库函数排序耗时" + duration + "毫秒。");
        }
    }

    private static boolean checkResult(int[] sortedByLib, int[] sortedByMyMethod) {
        for (int i = 0; i <= sortedByLib.length - 1; i++) {
            if (sortedByLib[i] != sortedByMyMethod[i]) return false;
        }
        return true;
    }
}
